package com.shop.service.impl;

import com.shop.dao.ProductMapper;
import com.shop.domain.Product;
import com.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper; // 【Mapper接口】做【dao提供】, SM高级,

    @Override
    public List<Product> getProductList() {

//        List<Product> products = this.productMapper.selectByExample(null);
        List<Product> products = this.productMapper.selectByExampleWithBLOBs(null);

        return products;
    }

    @Override
    public Product getProductById(String id) {
        Product product = this.productMapper.selectByPrimaryKey(Integer.parseInt(id));

        return product;
    }

    @Override
    public void updateitem(Product product) {

        this.productMapper.updateByPrimaryKeySelective(product);
    }

    @Override
    public int deleteAllItem(String[] ids) {

        int count = 0;

        for (String id : ids) {
            int i = this.productMapper.deleteByPrimaryKey(Integer.parseInt(id));

            if (i != 0) {
                count++;
            }
        }

        return count;
    }
}
